import {createStore} from 'vuex'

export default createStore({
	state:{
		userInfo:null,
		fromUserInfo:null,
	},
	
	getters:{
		getIsNotShare: state =>{//不是分享进来的
			if(state.fromUserInfo == null){
				return true
			}
			return false
		},
		
		getSearchQyId: state=>{ //获取当前显示的企业ID
			if(state.fromUserInfo !== null){
				return state.fromUserInfo.qyId !== undefined ? state.fromUserInfo.qyId : ''
			}else{
				return state.userInfo.qyId !== undefined ? state.userInfo.qyId : ''
			}
		},
		
		getSearchUserId:state=>{
			console.log(state.fromUserInfo, state.userInfo)
			if(state.fromUserInfo !== null){
				return state.fromUserInfo._id !== undefined ? state.fromUserInfo._id : ''
			}else{
				return state.userInfo._id !== undefined ? state.userInfo._id : ''
			}
		},
		
		getUserInfo:state=>{
			return state.userInfo
		},
		
		getFromUserInfo:state=>{
			return state.fromUserInfo
		},
		
		getUserId: state =>{
			return state.userInfo._id
		},
		
		getMyQyId: state =>{ //获得我的企业ID
			return state.userInfo.qyId !== undefined ? state.userInfo.qyId : ''
		}
	},
	
	mutations:{

		
		setUserInfo(state, userInfo){
			state.userInfo = userInfo
			console.log("state.userInfo", state.userInfo)
		},
		
		setFromUserInfo(state, fromUserInfo){
			state.fromUserInfo = fromUserInfo
		},
	}
})